<%--
  Created by IntelliJ IDEA.
  User: Scitt.lee
  Date: 15-10-9
  Time: 下午1:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>补丁制作页面</title>
    <script src="easyui/jquery.min.js"></script>
    <script src="easyui/jquery.easyui.min.js"></script>
    <link rel="stylesheet" href="easyui/themes/icon.css"/>
    <link rel="stylesheet" href="easyui/themes/default/easyui.css"/>
</head>
<body>

<form id="form1" runat="server" style="height: 800px;">
    <div style="width:80%">
        <ul id="fileTree">
        </ul>
    </div>

</form>
<div id="rightMenu" class="easyui-menu" style="width:120px;">
    <c:forEach var="role" items="${USER_KEY.roles}">
        <c:if test="${role=='update'}">
            <div onclick="updatePatchDialog()" data-options="iconCls:'icon-add'">升级</div>
        </c:if>
        <c:if test="${role=='rollback'}">
            <div onclick="updatePatchDialog()" data-options="iconCls:'icon-add'">回滚</div>
        </c:if>
    </c:forEach>
</div>


<div id="updatePatchDialog"></div>


<script>

    var currentPath;
    $(function () {
        $(document).ready(function () {
            $("#fileTree").tree({
                url: "/getPatchTree",
                line: true,
                data: [{
                    text: 'patch',
                    state: 'closed',
                    id: '/patch'
                }],
                onExpand: function (node, param) {
//                    console.info(node.id);
                    //$('#fileTree').tree('options').url = "/getPatchTree?pid=" + node.id;// change the url
                    $.post("/getPatchTree", {
                        "pid": node.id
                    }, function (json) {
                        $('#getPatchTree').tree('append', {
                            parent: node.target,
                            data: json.data
                        });
                    }, "json");

                },
                onContextMenu: function (e, node) {

                    e.preventDefault();
                    // 查找节点
                    $('#fileTree').tree('select', node.target);
                    currentPath = node.id;
//                    console.info(currentPath);
                    if ((node.text).endsWith('.tar.gz')) {
                        // 显示新增补丁快捷菜单
                        $('#rightMenu').menu('show', {
                            left: e.pageX,
                            top: e.pageY
                        });
                    }

                }
            });

        });

    });
    function removePatch() {
        $.messager.alert
        ({
            title: '提示',
            msg: '暂未开放',
            timeout: 5000
        });
    }

    function addPatch() {
        $.messager.alert
        ({
            title: '提示',
            msg: '暂未开放',
            timeout: 5000
        });
    }
    function updatePatchDialog() {
//        alert(currentPath);
        $('#updatePatchDialog').dialog({
            title: 'My Dialog',
            width: 800,
            height: 600,
            closed: false,
            cache: false,
            href: '/preUpdatePatch?patchName=' + currentPath,
            modal: true
        });
    }

    function commitPatchDirectory() {

        var directoryName = $("input[name='directoryName']").val();
        $.ajax
        ({
            type: 'post',
            data: {
                currentPath: currentPath,
                directoryName: directoryName
            },
            url: '/addPatchDirectory',
            dataType: 'json',
            success: function (date) {
                if (date.success) {
                    $.messager.alert
                    ({
                        title: 'Success',
                        msg: '添加目录成功',
                        timeout: 5000
                    });

                }
                else {
                    $.messager.alert
                    ({
                        title: 'Faild',
                        msg: '添加目录失败',
                        timeout: 5000
                    });
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.alert({
                    title: 'Faild',
                    msg: '添加目录失败',
                    timeout: 5000
                });
            }
        });
    }
    //iframe 父窗体自适应高度
    function iframeHeight() {
        var ifm = window.parent.document.getElementById("mainFrame");
        if (ifm != null) {
            ifm.height = $("body").height();
        }
    }
    iframeHeight();
</script>
</body>
</html>
